package com.loukou.lkt.lkt.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.loukou.lkt.lkt.dao.WarehouseDao;
import com.loukou.lkt.lkt.entity.Warehouse;
import com.loukou.lkt.lkt.resp.WarehouseDto;
import com.loukou.lkt.lkt.service.WarehouseService;

@Service
public class WarehouseServiceImpl implements WarehouseService{

	@Autowired
	WarehouseDao warehouseDao;
	
	@Override
	public List<WarehouseDto> getAllWarehouseInfo() {
		List<Warehouse> list = warehouseDao.findByWarehouseState(1);
		List<WarehouseDto> res = new ArrayList<WarehouseDto>();
		for(Warehouse warehouse : list){
			WarehouseDto warehouseDto = new WarehouseDto();
			warehouseDto.setAddress(warehouse.getWarehouseAddress());
			warehouseDto.setId(warehouse.getWarehouseId());
			warehouseDto.setCity(warehouse.getCityId());
			warehouseDto.setCode(warehouse.getWarehouseCode());
			warehouseDto.setName(warehouse.getWarehouseName());
			warehouseDto.setPerson(warehouse.getContractPerson());
			warehouseDto.setType(warehouse.getWarehouseType());
			res.add(warehouseDto);
		}
		return res;
	}

	@Override
	public Warehouse getWarehouse(int id) {
		
		return warehouseDao.findByWarehouseId(id);
	}
	
}
